package com.ztgf.shopping.api.common.convert;

import com.alibaba.fastjson.JSONObject;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.StrUtils;
import com.ztgf.order.models.bo.purchase.PurchaseCommoditySaveBO;
import com.ztgf.dubbo.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.converter.Converter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: mxli
 * @Date: 2020-12-23 23:14
 **/
@Slf4j
public class PurchaseCommodityBOListConverter implements Converter<String, List<PurchaseCommoditySaveBO>> {

    @Override
    public List<PurchaseCommoditySaveBO> convert(String s) throws ServiceException {
        try {

            List<PurchaseCommoditySaveBO> list = new ArrayList<>();
            if(StrUtils.isNotEmpty(s)){
                list = JSONObject.parseArray(s, PurchaseCommoditySaveBO.class);
            }
            return  list;

        } catch (Exception e) {
            throw new ServiceException(CodeEnum.FAIL_100002);
        }
    }
}
